package runesim.shared;
import java.util.*;
import java.io.*;
/**
 * Holds values for various node-specific values.
 * 
 * @author Ben
 */
public class Configuration {
	
	/**
	 * Load the configuration file.
	 */
	public static void load() {
		if(hasLoadedConfig) {
			Prompt.println("Configuration already loaded!");
		} else {
			try {
				properties = new Properties();
				properties.load(new FileInputStream(new File("config.ini")));
				
				port = Integer.parseInt(properties.getProperty("node_port", "43594"));
				quiet_mode = Boolean.parseBoolean(properties.getProperty("quiet_mode", "false"));
				protocol_version = Integer.parseInt(properties.getProperty("protocol_version", "317"));
				
				hasLoadedConfig = true;
			} catch(Exception e) {
				Prompt.println("Failed to load configuration! Exiting!");
				System.exit(1);
			}
		}
	}
	
	/**
	 * Gets the properties instance to use for configuration values.
	 * 
	 * @return The properties instance.
	 */
	public static Properties get() {
		if(hasLoadedConfig)
			return properties;
		else {
			System.out.println("Props not loaded!");
			return null;
		}
	}
	
	static Properties properties = null;
	static boolean hasLoadedConfig;
	
	// Configuration values
	
	public static int getPort() {
		return port;
	}
	
	public static boolean isUsingQuietMode() {
		return quiet_mode;
	}
	
	public static int getProtocolVersion() {
		return protocol_version;
	}
	
	static int port = 43594;
	static boolean quiet_mode = false;
	static int protocol_version = 317;
}
